class Solution {
public:
    int totalFruit(vector<int>& fruits) 
    {
        unordered_map<int,int> mp;
        int left=0,right=0,ret=0; 
        for (;right<fruits.size();right++)
        {
            mp[fruits[right]]++;
            if (mp.size()==3)
            {
                while (mp.size()==3)
                {
                    mp[fruits[left++]]--;
                    if (mp[fruits[left-1]]==0)
                        mp.erase(fruits[left-1]);
                }
            }  
            ret=max(ret,right-left+1);
        }
        return ret;
    }
};





